# name : alpha bound of spending function using pmvnorm
# key : alpha_bound_pmvnorm
# contributor: Shuguang Sun
# --
${1:spend_obf} <- function(alpha_fa, m = c(0, 0), v, alpha_ia, alpha = 0.025) {
  z1 <- qnorm(1 - alpha_ia)

  z <- qnorm(1 - alpha_fa)
  ret <- alpha - (pmvnorm(lower = c(-z1, -Inf), upper =  c(Inf, -z), mean = m, sigma = v) + alpha_ia)

  ret^2
}

${3:v} <- matrix(c(1, sqrt(${2:t}), sqrt($2), 1), nrow=2, ncol=2, byrow=FALSE)

optimize($1, interval = c(0.0001, 0.025), m = c(0, 0), v = $3, alpha_ia = ${4:0.011})
